<%@ include file="/common/taglibs.jsp"%>
<!--分页查询共用的页面-->
<%@ include file="/common/common.jsp"%>
<%@ include file="/common/dateUtil.jsp"%>
<%@ page language="java" pageEncoding="UTF-8"%>
<head>

<script>


////////////////////////////////////////////////////////变量
var adas_len = {};
adas_len.debug = true;


adas_len.bas = {};
adas_len.bas.activeName = "主动安全报警";
adas_len.bas.alarmList = [];//报警基本数据列表
adas_len.bas.activeAlarmList = [];//主动安全报警列表
adas_len.bas.activeAlarmMap = {};//主动安全报警基本数据map
adas_len.bas.slctPageUrl = globalConfig.webPath + '/basicSlctAction/selectPaginationDataByAuth.action';


//初始化控件,页面加载时即加载，不需要调用
$(function(){
    // console.log("开始初始化数据表格");
    //初始化表格
    $("#adas_len_DataGrid").datagrid({
        height:"100%",
        // toolbar:"#allAlarmsToobar",//工具条
        pagination:true,//分页工具栏
		pageList:[15,30,50,100],
		pageSize:15,
		singleSelect:true,//单选
		rownumbers:true,//行号
		striped:true,//隔行变色
		fitColumns: false,//填充列
		checkOnSelect: false,//选中则勾选
        selectOnCheck: false,//勾选则选中
        
    });
    //选择页面事件定义
	$("#adas_len_DataGrid").datagrid("getPager").pagination({
		onSelectPage:function(pageNumber,pageSize){
			adas_len.getAlarmDatas(pageNumber);	
		}
	});
});

////////////////////////////////////////////////////////初始化控件前初始化数据

adas_len.initDataBeforeInitDiv = function(){
    let that = this;
    that.bas.activeAlarmList = [];
    that.bas.activeAlarmMap = {};
    let alarmList = JSON.parse(window.localStorage.getItem("alarmSourceList"));
    // that.outDebug("报警列表:" , alarmList);
    if(!DataUtil.isDefined(alarmList.length) && alarmList.length > 0){
        that.bas.alarmList = alarmList;//保存报警基本数据列表
        let list = [{text:'请选择',value:''}];
        $.each(alarmList,function(n,item){
            if(item.alarmSourceName == adas_len.bas.activeName){
                //主动安全报警
                let key = item.alarmSource + '_' + item.alarmType;
                let obj = {
                    text:item.alarmTypeName,
                    value:key
                };
                list.push(obj);
                that.bas.activeAlarmMap[key] = item;
            }
        });
        that.bas.activeAlarmList = list;
    }

}


////////////////////////////////////////////////////////初始化
adas_len.initDivs = function(){
    this.outDebug("start init Divs ! ");
    this.initDataBeforeInitDiv();
    this.initDepDiv();
    this.initTimeDivs();
    this.initAlarmTypeDiv();
    this.initAlarmLevelDiv();
}

//初始化车组控件
adas_len.initDepDiv = function(){
    //创建下拉部门树
    Utility.createDepTree("adas_len_DepId");
}

//初始化时间控件
adas_len.initTimeDivs = function(){
    let today = Utility.today();
    $("#adas_len_StartTime").datetimebox('setValue',today + ' 00:00:00');
    $("#adas_len_EndTime").datetimebox('setValue',today + ' 23:59:59');
}

//初始化报警类型控件
adas_len.initAlarmTypeDiv = function(){
    let list = this.bas.activeAlarmList;
    $("#adas_len_AlarmType").combobox({
        textField: "text",
        valueField: "value",
        data: list,
        select: list[0].value,
        onChange:adas_len.alarmTypeChangeFun
    });

    //初始化报警参数控件值
    $("#adas_len_AlarmType_1").val("");
    $("#adas_len_alarmSource").val("");
}

//初始化报警级别控件
adas_len.initAlarmLevelDiv = function(){
    let list = [
        {text:'请选择',value:''},
        {text:'一级',value:'1'},
        {text:'二级',value:'2'},
    ];
    $("#adas_len_alarmLevel").combobox({
        textField: "text",
        valueField: "value",
        data: list,
        select: list[0].value,
    });
}



////////////////////////////////////////////////////////加载数据
//获取报警数据
adas_len.getAlarmDatas = function(pageNumber){
    let that = this;
    let param = this.getQueryParam(pageNumber);
    this.outDebug("查询所需参数为：" , param);
    if(param.message == ""){
        Utility.showLoading();
        Utility.getAjaxData(that.bas.slctPageUrl,JSON.stringify(param),function(data){
            Utility.hideLoading();
            that.outDebug("接收到报警时长相关结果数据：" , data);
            if(data.success){
                if(data.data != null){
                    $("#adas_len_DataGrid").datagrid('loadData',data.data);
                }
            }else{
                DataUtil.showErrorMsg(data.message);
            }
        });
    }else{
        DataUtil.showErrorMsg(param.message);
    }
}

//获取报警查询所需参数
adas_len.getQueryParam = function(pageNumber){
    let param = DataUtil.getParamFromForm("adas_len_QueryForm");
    if(param.message == ""){
        //获取分页参数
        param.pageSize = $("#adas_len_DataGrid").datagrid("getPager").data("pagination").options.pageSize;
        if(!isNaN(pageNumber) && pageNumber > 0){
            param.pageNumber = pageNumber;
        }else{
            param.pageNumber = $("#adas_len_DataGrid").datagrid("getPager").data("pagination").options.pageNumber;
        }
    }

    //校验报警时长
    // this.outDebug("报警时长值为为：" + parseInt(param.alarmTimeLength));
    if(isNaN(parseInt(param.alarmTimeLength))){
        // this.outDebug("报警时长不合法！");
        delete param.alarmTimeLength;
    }
    return param;
}



////////////////////////////////////////////////////////控件事件
//报警类型选择事件
adas_len.alarmTypeChangeFun = function(value){
    // let value = $("#adas_len_AlarmType").combobox('getValue');
    // adas_len.outDebug('报警类型选择事件,选择数据为：' , value);
    adas_len.outDebug("控件输入参数：" , value);
    if(value == ""){
        //选择空
        $("#adas_len_AlarmType_1").val("");
        $("#adas_len_alarmSource").val("");
    }else{
        //选择非空
        let obj = adas_len.bas.activeAlarmMap[value];
        if(!DataUtil.isDefined(obj)){
            $("#adas_len_alarmSource").val(obj.alarmSource);
            $("#adas_len_AlarmType_1").val(obj.alarmType);
        }
    }
}




////////////////////////////////////////////////////////公用方法
//输出调试信息
adas_len.outDebug = function(msg,data){
    if(this.debug == true){
        DataUtil.outDebug(msg,data);
    }
}



////////////////////////////////////////////////////////加载后执行
$(document).ready(function(){
    // adas_len.outDebug("ready");
    adas_len.initDivs();
});


</script>
</head>
<body style="background-color:rgb(251,251,251);height:98%;width:99%;" class="base_ver_flexStartDiv_css">
    <div id="adas_len_Toobar" style="width:100%;" class="sh_css_basFontSize">
        <form id="adas_len_QueryForm" action="<%=ApplicationPath%>/export.action">
            <input type="hidden" name="queryId" value="reportV2.selectAdasAlarmTimeLengthDatas" />
            <input type="hidden" name="fileName" value="主动安全报警分析表" />
            <input type="hidden" id="adas_len_AlarmType_1" name="alarmType" value="" />
            <input type="hidden" id="adas_len_alarmSource" name="alarmSource" value="" />

            <!--上层按钮栏-->
            <div style="width:80%;margin-left: 15px;margin-top:5px;">
                <a id="adas_len_BtnExport" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-excel'" style="display:none;">导出</a>
                &nbsp;&nbsp;
                <a id="adas_len_BtnReset" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-clear'">重置</a>
            </div>
            <!--下层查询工具栏-->
            <hr>
            <div style="width:100%;height:45px;" class="base_hori_flexStartDiv_css">
                <!--左侧条件样式-->
                <div style="height:100%;margin-top:7px;margin-left:10px;" class="base_ver_Around_leftDiv_css">
                    <div>
                        组织
                        <select id="adas_len_DepId" name="depId" style="width:170px;"></select>
                        &nbsp;
                        车辆
                        <input id="adas_len_PlateNo" type="text" name="plateNo" style="width:100px;">
                        &nbsp;
                        起止时间
                        <input type="text" name="startTime" id="adas_len_StartTime" class="easyui-datetimebox" style="width:150px;" />
                        <span>-</span>
                        <input type="text" name="endTime" id="adas_len_EndTime" class="easyui-datetimebox" style="width:150px;" />
                    </div>
                    <div style="margin-top:7px;">
                        报警类型
                        <select id="adas_len_AlarmType" style="width:150px;"></select>
                        &nbsp;
                        速度>=
                        <input type="text" name="speed" style="width:50px;">(km/h)
                        &nbsp;
                        报警级别
                        <select id="adas_len_alarmLevel" name="level" style="width:80px;"></select>
                        &nbsp;
                        报警时长 >=
                        <input type="text" name="alarmTimeLength" style="width:40px;">(秒)
                        &nbsp;
                        驾驶员
                        <input type="text" name="driverName" style="width:80px;">
                    </div>
                </div>
                <!--右侧按钮-->
                <div style="margin-left:20px;" class="base_hori_flexCenterDiv_css">
                    <!-- <a id="adas_len_BtnQuery" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" 
                    onclick="javascript:adas_len.getAlarmDatas();">查询</a> -->
                    <div id="adas_len_BtnQuery" class="sh_css_btn" onclick="javascript:adas_len.getAlarmDatas();">
                        <div class="ui-icon icon-search" style="width:16px;height:16px;"></div>
                        <span>查询</span>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <table id="adas_len_DataGrid" class="easyui-datagrid" style="width:100%;">
        <thead>
            <tr>
                <th data-options="field:'depName'" width="100">组织名称</th>
                 <th data-options="field:'plateNo'" width="80">车牌号码</th>
                 <th data-options="field:'driverName'" width="80">驾驶员</th>
                 <th data-options="field:'alarmTypeName'" width=" 100">报警类型</th>
                 <th data-options="field:'alarmTime'" width="140">报警时间</th>
                 <th data-options="field:'alarmEndDate'" width="140">报警结束时间</th>
                 <th data-options="field:'alarmTimeLength'" width="90">报警时长(秒)</th>
                 <th data-options="field:'level'" width="70">报警等级</th>
                 <th data-options="field:'processedTime'" width="140">报警处理时间</th>
                 <th data-options="field:'speed'" width="70">速度(km/h)</th>
                 <th data-options="field:'latitude'" width="80">纬度</th>
                 <th data-options="field:'longitude'" width="80">经度</th>
                 <th data-options="field:'altitude'" width="80">海拔(米)</th>
                 <th data-options="field:'simNo'" width="110">通讯SIM卡号</th>
                <th data-options="field:'location'" width="280">位置</th>
            </tr>
        </thead>
    </table>
</body>